home *** CD-ROM | disk | FTP | other *** search
/ Champak 66 / Vol 66.iso / games / bob_espo.swf / scripts / __Packages / AtlantisBus.as < prev    next >
Text File  |  2013-04-24  |  7KB  |  228 lines

  1. class AtlantisBus extends MovingObject
  2. {
  3.    static var sLINKAGE_NAME = "mcAtlantisBus";
  4.    static var nMOVE_UP = Key.UP;
  5.    static var nMOVE_DOWN = Key.DOWN;
  6.    static var nMOVE_LEFT = Key.LEFT;
  7.    static var nMOVE_RIGHT = Key.RIGHT;
  8.    static var nNO_KEY = -99;
  9.    static var nEASTER_EGG = 83;
  10.    static var nSPEED = 1;
  11.    static var nINITIAL_X = 10;
  12.    static var nINITIAL_Y = 170;
  13.    function AtlantisBus()
  14.    {
  15.       super(CTRLGame.getRef().mcRef.attachMovie(AtlantisBus.sLINKAGE_NAME,AtlantisBus.sLINKAGE_NAME,CTRLGame.getRef().calculateDepth(AtlantisBus.nINITIAL_Y,CTRLGame.nBUS_ADD)));
  16.       this.mcRef._x = AtlantisBus.nINITIAL_X;
  17.       this.mcRef._y = AtlantisBus.nINITIAL_Y;
  18.       this.bKeyEasterPressed = false;
  19.       if(!Main.getRef().EasterEgg)
  20.       {
  21.          this.nKeyMoveUp = AtlantisBus.nMOVE_UP;
  22.          this.nKeyMoveDown = AtlantisBus.nMOVE_DOWN;
  23.          this.nKeyMoveLeft = AtlantisBus.nMOVE_LEFT;
  24.          this.nKeyMoveRight = AtlantisBus.nMOVE_RIGHT;
  25.       }
  26.       else
  27.       {
  28.          this.nKeyMoveUp = AtlantisBus.nMOVE_DOWN;
  29.          this.nKeyMoveDown = AtlantisBus.nMOVE_UP;
  30.          this.nKeyMoveLeft = AtlantisBus.nMOVE_RIGHT;
  31.          this.nKeyMoveRight = AtlantisBus.nMOVE_LEFT;
  32.       }
  33.    }
  34.    function cleanUp()
  35.    {
  36.       super.cleanUp();
  37.       this.mcRef.swapDepths(7777);
  38.       this.mcRef.removeMovieClip();
  39.    }
  40.    function doUnPause()
  41.    {
  42.       if(!CTRLGame.getRef().Screen.isInMiniGame())
  43.       {
  44.          super.doUnPause();
  45.       }
  46.    }
  47.    function resumeAnim()
  48.    {
  49.       super.doUnPause();
  50.    }
  51.    function checkObjects()
  52.    {
  53.       CTRLGame.getRef().checkPowerUps();
  54.       CTRLGame.getRef().checkAlgaes();
  55.       CTRLGame.getRef().checkJellys();
  56.       CTRLGame.getRef().checkDirtWalls();
  57.       CTRLGame.getRef().checkFinish();
  58.    }
  59.    function manageMovement()
  60.    {
  61.       this.setupKeys();
  62.       if(this.canMove() && this.nMovement == 0)
  63.       {
  64.          var _loc2_ = this.nCurrentDir;
  65.          if(Key.isDown(this.nKeyMoveUp))
  66.          {
  67.             if(this.isNextMoveGood(CTRLGame.nDIR_UP))
  68.             {
  69.                this.setState(MovingObject.sSTATE_UP);
  70.                this.nCurrentDir = CTRLGame.nDIR_UP;
  71.                this.nMovement = MovingObject.nMAX_MOVEMENT;
  72.             }
  73.          }
  74.          else if(Key.isDown(this.nKeyMoveDown))
  75.          {
  76.             if(this.isNextMoveGood(CTRLGame.nDIR_DOWN))
  77.             {
  78.                this.setState(MovingObject.sSTATE_DOWN);
  79.                this.nCurrentDir = CTRLGame.nDIR_DOWN;
  80.                this.nMovement = MovingObject.nMAX_MOVEMENT;
  81.             }
  82.          }
  83.          else if(Key.isDown(this.nKeyMoveLeft))
  84.          {
  85.             if(this.isNextMoveGood(CTRLGame.nDIR_LEFT))
  86.             {
  87.                this.setState(MovingObject.sSTATE_LEFT);
  88.                this.nCurrentDir = CTRLGame.nDIR_LEFT;
  89.                this.nMovement = MovingObject.nMAX_MOVEMENT;
  90.             }
  91.          }
  92.          else if(Key.isDown(this.nKeyMoveRight))
  93.          {
  94.             if(this.isNextMoveGood(CTRLGame.nDIR_RIGHT))
  95.             {
  96.                this.setState(MovingObject.sSTATE_RIGHT);
  97.                this.nCurrentDir = CTRLGame.nDIR_RIGHT;
  98.                this.nMovement = MovingObject.nMAX_MOVEMENT;
  99.             }
  100.          }
  101.          if(this.nMovement == 0)
  102.          {
  103.             switch(this.nCurrentDir)
  104.             {
  105.                case CTRLGame.nDIR_UP:
  106.                   this.setState(MovingObject.sSTATE_IDLE_UP);
  107.                   break;
  108.                case CTRLGame.nDIR_DOWN:
  109.                   this.setState(MovingObject.sSTATE_IDLE_DOWN);
  110.                   break;
  111.                case CTRLGame.nDIR_LEFT:
  112.                   this.setState(MovingObject.sSTATE_IDLE_LEFT);
  113.                   break;
  114.                case CTRLGame.nDIR_RIGHT:
  115.                   this.setState(MovingObject.sSTATE_IDLE_RIGHT);
  116.             }
  117.          }
  118.          CTRLGame.getRef().Screen.manageAnim(this.nCurrentDir,_loc2_,this.nMovement);
  119.       }
  120.    }
  121.    function setupKeys()
  122.    {
  123.       if(this.canMove())
  124.       {
  125.          if(!Key.isDown(AtlantisBus.nEASTER_EGG))
  126.          {
  127.             this.bKeyEasterPressed = false;
  128.          }
  129.          else if(Key.isDown(AtlantisBus.nEASTER_EGG) && (!Main.getRef().EasterEgg && !this.bKeyEasterPressed))
  130.          {
  131.             Main.getRef().setEasterEgg(true);
  132.             this.bKeyEasterPressed = true;
  133.             this.nKeyMoveUp = AtlantisBus.nMOVE_DOWN;
  134.             this.nKeyMoveDown = AtlantisBus.nMOVE_UP;
  135.             this.nKeyMoveLeft = AtlantisBus.nMOVE_RIGHT;
  136.             this.nKeyMoveRight = AtlantisBus.nMOVE_LEFT;
  137.          }
  138.          else if(Key.isDown(AtlantisBus.nEASTER_EGG) && (Main.getRef().EasterEgg && !this.bKeyEasterPressed))
  139.          {
  140.             Main.getRef().setEasterEgg(false);
  141.             this.bKeyEasterPressed = true;
  142.             this.nKeyMoveUp = AtlantisBus.nMOVE_UP;
  143.             this.nKeyMoveDown = AtlantisBus.nMOVE_DOWN;
  144.             this.nKeyMoveLeft = AtlantisBus.nMOVE_LEFT;
  145.             this.nKeyMoveRight = AtlantisBus.nMOVE_RIGHT;
  146.          }
  147.       }
  148.    }
  149.    function isNextMoveGood(_nNextDir)
  150.    {
  151.       var _loc3_ = this.getWishMidPos(_nNextDir);
  152.       var _loc4_ = false;
  153.       if(this.isTrackOkay(_nNextDir) && !CTRLGame.getRef().isTouchingWall(_loc3_.x,_loc3_.y))
  154.       {
  155.          _loc4_ = true;
  156.       }
  157.       return _loc4_;
  158.    }
  159.    function adaptDepth()
  160.    {
  161.       this.mcRef.swapDepths(CTRLGame.getRef().calculateDepth(this.mcRef._y,CTRLGame.nBUS_ADD));
  162.    }
  163.    function manageIdle()
  164.    {
  165.       this.manageMovement();
  166.       CTRLGame.getRef().checkJellys();
  167.       CTRLGame.getRef().checkAlgaes();
  168.    }
  169.    function IdleUp()
  170.    {
  171.       this.manageIdle();
  172.    }
  173.    function IdleDown()
  174.    {
  175.       this.manageIdle();
  176.    }
  177.    function IdleLeft()
  178.    {
  179.       this.manageIdle();
  180.    }
  181.    function IdleRight()
  182.    {
  183.       this.manageIdle();
  184.    }
  185.    function Left()
  186.    {
  187.       if(this.nMovement > 0 && this.canMove())
  188.       {
  189.          this.mcRef._x -= AtlantisBus.nSPEED;
  190.          this.nMovement -= AtlantisBus.nSPEED;
  191.          this.checkObjects();
  192.       }
  193.       this.manageMovement();
  194.    }
  195.    function Up()
  196.    {
  197.       if(this.nMovement > 0 && this.canMove())
  198.       {
  199.          this.mcRef._y -= AtlantisBus.nSPEED;
  200.          this.nMovement -= AtlantisBus.nSPEED;
  201.          this.adaptDepth();
  202.          this.checkObjects();
  203.       }
  204.       this.manageMovement();
  205.    }
  206.    function Right()
  207.    {
  208.       if(this.nMovement > 0 && this.canMove())
  209.       {
  210.          this.mcRef._x += AtlantisBus.nSPEED;
  211.          this.nMovement -= AtlantisBus.nSPEED;
  212.          this.checkObjects();
  213.       }
  214.       this.manageMovement();
  215.    }
  216.    function Down()
  217.    {
  218.       if(this.nMovement > 0 && this.canMove())
  219.       {
  220.          this.mcRef._y += AtlantisBus.nSPEED;
  221.          this.nMovement -= AtlantisBus.nSPEED;
  222.          this.adaptDepth();
  223.          this.checkObjects();
  224.       }
  225.       this.manageMovement();
  226.    }
  227. }
  228.